package com.jd.util;

import com.google.common.base.CaseFormat;

import java.util.Random;
import java.util.UUID;



/**
 * @author yang
 */
public class StringUtils extends org.apache.commons.lang3.StringUtils {

    private StringUtils() {}

    public static boolean isEmpty(String str)
    {
        return str == null || str.length() == 0;
    }

    /**
     * 下划线转驼峰
     * @param s
     * @return
     */
    public static String lowerCamel(String s) {
        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, s);
    }

    /**
     * 驼峰转下划线
     * @param s
     * @return
     */
    public static String lowerUnderscore (String s ) {
        return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, s);
    }


    public static String generateUUID(){
        return UUID.randomUUID().toString().replace("-","");
    }

    /**
     * 获取count个随机数
     * @param length 随机数个数
     * @return
     */
    public static Long game(int length){
        StringBuilder val = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            val.append(random.nextInt(10));
        }
        return Long.valueOf(val.toString());
    }
    public static String getNo12(Long val){
        int size = val.toString().length();
        if(size < 12){
            return val + game(12 - size).toString();
        }
        return val.toString().substring(0, 12);
    }


    public static String getString(Object obj, String defult){
        if(obj == null){
            return defult;
        }
        return obj.toString();
    }
}
